﻿using System.Collections.Generic;
using Core.SimpleTemp.Common;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories.Internal;
using Core.Toolkit.AutoMapperExtend.DataDictionary;
using System.Linq;
namespace Core.SimpleTemp.Repositories.Sys
{
    [AutoDi()]
    [AutoDi(typeof(IDataDicProvider))]
    public class SysDataDicRepository : BaseDBRepository<SysDataDic>, IDataDicProvider
    {
        public SysDataDicRepository(CoreDBContext dbContext) : base(dbContext)
        {
        }

        public void LoadData(Dictionary<string, string> _dataDic, Dictionary<string, List<DataDicModel>> _dataDicListByCategory)
        {

            var dataDivList = QueryBase().ToList();
            foreach (var item in dataDivList)
            {
                _dataDic.TryAdd($"{item.Category}_{item.Key}", item.Value);
            }


            var dataDicGroup = dataDivList.GroupBy(obj => obj.Category);
            foreach (var item in dataDicGroup)
            {
                _dataDicListByCategory.TryAdd(item.Key, item.ToList().Select(sdd => new DataDicModel()
                {
                    Category = sdd.Category,
                    Key = sdd.Key,
                    Value = sdd.Value
                }).ToList());
            }
        }
    }
}
